-- @owner: wang-tianjing1
-- @date: 2024-08-12
-- @testpoint: 闪回到一次插入多条数据后的时间点

--step1：建表     expect：成功
drop table if exists reason_t2;
CREATE OR REPLACE FUNCTION findCsn(int8)
  RETURNS INTEGER
  LANGUAGE plpgsql
AS
$BODY$
declare
  count integer;
begin
  count = (select snapcsn from t_timecapsule_test_tmp where id =  $1);
  return count;
end;
$BODY$;
delete from t_timecapsule_test_tmp;
drop table if exists reason_t2;
purge recyclebin;

CREATE TABLE reason_t2
(
  r_reason_sk    integer,
  r_reason_id    character(16),
  r_reason_desc  character(100)
);
select pg_sleep(4);

--step2：插入数据    expect：成功
insert into t_timecapsule_test_tmp select 1, now(), int8in(xidout(next_csn)) from gs_get_next_xid_csn();
INSERT INTO reason_t2 VALUES (3, 'AAAAAAAACAAAAAAA','reason3'),(4, 'AAAAAAAADAAAAAAA', 'reason4'),(5, 'AAAAAAAAEAAAAAAA','reason5');
select pg_sleep(4);
insert into t_timecapsule_test_tmp select 2, now(), int8in(xidout(next_csn)) from gs_get_next_xid_csn();

--step3：闪回查询     expect：成功
insert into t_timecapsule_test_tmp select 1, now(), int8in(xidout(next_csn)) from gs_get_next_xid_csn();

INSERT INTO reason_t2 VALUES (3, 'AAAAAAAACAAAAAAA','reason3'),(4, 'AAAAAAAADAAAAAAA', 'reason4'),(5, 'AAAAAAAAEAAAAAAA','reason5');
select pg_sleep(4);
insert into t_timecapsule_test_tmp select 2, now(), int8in(xidout(next_csn)) from gs_get_next_xid_csn();

--step4：清理环境    expect：成功
drop table if exists reason_t2;
purge recyclebin;